package com.tt.ProxyFactory;

import com.tt.ProxyFactory.cglib.CglibTransactionProxy;
import com.tt.ProxyFactory.jdk.JdkTransactionProxy;
import com.tt.TransactionController.TransactionController;

import java.sql.Connection;
import java.sql.SQLException;
public class TransactionProxyFactory {

    private final Object target;
    private final TransactionController transactionController;

    public TransactionProxyFactory(Object target, TransactionController transactionController) {
        this.target = target;
        this.transactionController = transactionController;
    }

    public Object getProxyInstance() {
        if (target.getClass().getInterfaces().length > 0) {
            // JDK动态代理
            return new JdkTransactionProxy(target, transactionController).getProxyInstance();
        } else {
            // CGLIB动态代理
            return new CglibTransactionProxy(target, transactionController).getProxyInstance();
        }
    }
}